package com.kh.pajx.sop.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.BalanceAppDao;
import com.kh.pajx.sop.domain.BalanceApp;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.service.BalanceAppService;
import com.kh.pajx.sop.util.page.QueryHelper;
@Service
@Transactional
public class BalanceAppServiceImpl extends BaseServiceImpl<BalanceApp> implements BalanceAppService {
	private BalanceAppDao balanceAppDao;
	@Resource
	public void setBalanceAppDao(BalanceAppDao balanceAppDao) {
		this.balanceAppDao = balanceAppDao;
	}

	@Override
	public void addBalanceApp(BalanceApp pwfi) {
		balanceAppDao.save(pwfi);
		
	}

	@Override
	public void updateBalanceApp(BalanceApp pwfi) {
		balanceAppDao.update(pwfi);
		
	}

	@Override
	public void deleteBalanceApp(String uuid) {
		balanceAppDao.delete(uuid);
		
	}

	@Override
	public List<BalanceApp> searchBalanceApp(Map<String, String> params) {
		StringBuilder sb = new StringBuilder();
		String billState =params.get("billState");
		String user = params.get("user");
		sb.append("select ba from  BalanceApp ba where 1=1 ");
		if (user != null && !"".equals(user)) {
			sb.append(" and ba.appPerson ='").append(user).append("' ");
		}
		if (billState != null && !"".equals(billState)) {
			sb.append(" and ba.billState ='").append(billState).append("' ");
		}
		sb.append(" order by ba.appBillCode desc");
		return balanceAppDao.findList(sb.toString());
	}

	@Override
	public BalanceApp findBalanceAppById(String id) {
		return balanceAppDao.getById(id);
	}
	@Override
	public List<BalanceApp> getAllBalanceApp() {
		return balanceAppDao.findAll();
	}


	public BalanceAppDao getBalanceAppDao() {
		return balanceAppDao;
	}

	@Override
	public int GetMaxID() {
		String sql = "select nvl(max(APP_BILLCODE),'0') from YW_RPT_BALANCE_APP";
		Object o=balanceAppDao.getByJdbcSQL(sql).get(0);
		int maxId=Integer.parseInt(o.toString().replace("[", "").replace("]", ""));
		return maxId;
	}
	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return balanceAppDao.getPageBean(pageNum, pageSize, queryHelper);
	}
}
